from core.basehandler import BaseHandler
from core.room import Room
from items.test import test
from items.test2 import test2
from core.action import Action
from core.support import get_game


class classroom(Room):
    def __init__(self, room_id):
        Room.__init__(self, room_id)    # do basic initialization for every room
        
        # add inventory items
        self.add_item(test())
        self.add_item(test2())
        
        # build list of actions
        self.add_action(Exit)
            
    # return description of room.
    def get_description(self):
        if self.is_test_submitted2():
            return "You're done with classes!"
        elif self.is_test_submitted():
            return "One more test to go!"
        else:
            return 'You have arrived to class.  Get ready to take a test.'
        
    
    # return image of room. Image changes once test is taken
    def get_image(self):
        if self.is_test_taken():
            if self.is_test_taken2():
                return 'hard_test.jpg'
            elif self.is_test_submitted():
                return 'classroom.jpg'
            else:
                return 'Jackie-chan-meme.jpg'
        else:
            return 'classroom.jpg'
                
        
    # checks whether test has been taken or not
    def is_test_taken(self):
        game = get_game()
        player = game.get_player()
        if 'test' in player.inventory:
            if player.inventory['test'].test_taken:
                return True    
        # if we get here, the test has not been taken
        return False

    def is_test_submitted(self):
        game = get_game()
        player = game.get_player()
        if 'test' in player.inventory:
            if player.inventory['test'].test_submitted:
                return True    
        # if we get here, the test has not been taken
        return False


    def is_test_taken2(self):
        game = get_game()
        player = game.get_player()
        if 'test2' in player.inventory:
            if player.inventory['test2'].test_taken:
                return True    
        # if we get here, the test has not been taken
        return False 
    
    def is_test_submitted2(self):
        game = get_game()
        player = game.get_player()
        if 'test2' in player.inventory:
            if player.inventory['test2'].test_submitted:
                return True    
        # if we get here, the test has not been taken
        return False
    
class ClassRoomHandler(BaseHandler):
    
    # return class to use to create a new instance of this room
    def get_room_class(self):
        return classroom

# define actions for this room

class Exit(Action):
    def __init__(self):
        Action.__init__(self, "Exit")    # do basic initialization for every action

    # return description of action (used in label on webpage)
    def get_description(self):
        return "Go to Lobby"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'lobby'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"
    
    